﻿Imports System.IO
Imports System.Xml
Module LoadSector
#Region "Dimensions"
    Private InitialMap As String
#End Region
#Region "Functions"
    Private Function DecreaseByOne(ByVal value As Integer)
        value -= 1
        Return value
    End Function
    Private Function Recur(ByVal TheString As String) As String()
        Dim CurrentPosition, LastPosition As Short, TheResult(1) As String
        For CurrentPosition = 2 To Len(TheString) Step 1
            If Mid(LastPosition, CurrentPosition, 1) = "." Then
                TheResult(0) = Mid(LastPosition, 2, CurrentPosition - 1)
                LastPosition = CurrentPosition
            ElseIf Mid(LastPosition, CurrentPosition, 1) = "]" Then
                TheResult(1) = Mid(TheString, LastPosition + 1, CurrentPosition - 1)
                Exit For
            End If
        Next
        Return TheResult
    End Function
    Private Function Recur2(ByVal StartSearchPosition As Integer, ByVal SearchString As String, ByVal VNUM As String, Optional ByVal StartStringAtPeriod As Boolean = False, Optional ByVal Type As Boolean = False, Optional ByVal FailResult As String = "ERROR") As String()
        Dim findstr As String = SearchString + "#" + VNUM + "("
        Dim StartPosition, CurrentPosition As Integer, TheResult(1) As String
        If Type = False Then
            StartPosition = InStr(StartSearchPosition, MainProgram.MapHeaderData, findstr)
        Else
            Dim bob As String
            bob = MainProgram.MapData
            StartPosition = InStr(StartSearchPosition, MainProgram.MapData, findstr)
        End If
        If StartPosition > 0 Then
            If Type = False Then
                For CurrentPosition = StartPosition To Len(MainProgram.MapHeaderData) Step 1
                    If Mid(MainProgram.MapHeaderData, CurrentPosition, 1) = ")" Then
                        TheResult(0) = Mid(MainProgram.MapHeaderData, StartPosition, CurrentPosition - StartPosition)
                        TheResult(1) = LTrim(Str(CurrentPosition))
                        Exit For
                    ElseIf Mid(MainProgram.MapHeaderData, CurrentPosition, 1) = "." And StartStringAtPeriod = True Then
                        StartPosition = CurrentPosition + 1
                    ElseIf Mid(MainProgram.MapHeaderData, CurrentPosition, 1) = "(" And StartStringAtPeriod = False Then 'default is start string at (
                        StartPosition = CurrentPosition + 1
                    End If
                Next
            Else
                For CurrentPosition = StartPosition To Len(MainProgram.MapData) Step 1
                    If Mid(MainProgram.MapData, CurrentPosition, 1) = ")" Then
                        TheResult(0) = Mid(MainProgram.MapData, StartPosition, CurrentPosition - StartPosition)
                        TheResult(1) = LTrim(Str(CurrentPosition))
                        Exit For
                    ElseIf Mid(MainProgram.MapData, CurrentPosition, 1) = "." And StartStringAtPeriod = True Then
                        StartPosition = CurrentPosition + 1
                    ElseIf Mid(MainProgram.MapData, CurrentPosition, 1) = "(" And StartStringAtPeriod = False Then 'default is start string at (
                        StartPosition = CurrentPosition + 1
                    End If
                Next
            End If
        Else
            TheResult(0) = FailResult
            TheResult(1) = "-1" 'this ensures that the curser doesn't assume the current cursor position which is at the end of the file
            Return TheResult
        End If
        Return TheResult
    End Function
    Private Function DistributeEnvironmentVariables(ByVal Num As Short)
        Dim EnvironmentData As String = MainProgram.GetFileContents(MainProgram.DirEnvironments)
        Dim steps As Integer
        Dim StartPosition As Integer
        Dim Type As Short = 1
        steps = InStr(EnvironmentData, "[" + LTrim(Str(Num)) + ":")
        StartPosition = steps + Len(LTrim(Str(Num))) + 2
        If steps > 0 Then
            For steps = steps + 1 To Len(EnvironmentData) Step 1
                If Mid(EnvironmentData, steps, 1) = Chr(13) Or Mid(EnvironmentData, steps, 1) = Chr(11) Then
                    If Type = 1 Then 'environment name
                        MainProgram.MapData_EnvironString = Mid(EnvironmentData, StartPosition, steps - 1 - StartPosition)
                    ElseIf Type = 2 Then 'environment temperature
                        MainProgram.MapData_EnvironTemp = Val(Mid(EnvironmentData, StartPosition, steps - StartPosition))
                    ElseIf Type = 3 Then 'environment weather
                        MainProgram.MapData_EnvironWeather = Mid(EnvironmentData, StartPosition, steps - StartPosition)
                    ElseIf Type = 4 Then 'environment magic
                        MainProgram.MapData_EnvironMagic = Mid(EnvironmentData, StartPosition, steps - StartPosition)
                    ElseIf Type = 5 Then 'environment description
                        MainProgram.MapData_EnvironDesc = Mid(EnvironmentData, StartPosition, steps - StartPosition)
                        Exit For
                    End If
                    Type += 1
                    StartPosition = steps + 1
                ElseIf Mid(EnvironmentData, steps, 1) = "[" Then
                    MainProgram.SND("/RERROR 1660: Environment allocation fault.")
                    MainProgram.SND("/Y         Error supressed successfully, please report this.")
                    Exit For
                End If
            Next
        Else
            MainProgram.MapData_EnvironString = "Unknown"
            MainProgram.MapData_EnvironTemp = 3
            MainProgram.MapData_EnvironWeather = "0"
            MainProgram.MapData_EnvironMagic = "0"
            MainProgram.MapData_EnvironDesc = "Unknown environment."
        End If
        Return 0
    End Function
    Public Function SetEnvironmentColor(ByVal x As Short, ByVal y As Short, ByVal color As String)
        'declare xml dimensions
        Dim m_xmld As XmlDocument
        Dim m_nodelist As XmlNodeList
        Dim m_node As XmlNode
        Dim CurNumber As String, CurName As String
        Try
            m_xmld = New XmlDocument()
            m_xmld.Load(Replace(MainProgram.DirMapHeader, "MapHeader.TG", "Environments.xml"))
            m_nodelist = m_xmld.SelectNodes("/environmentlist/environment")
            For Each m_node In m_nodelist
                CurName = m_node.Attributes.GetNamedItem("name").Value
                CurNumber = m_node.Attributes.GetNamedItem("number").Value
                If Val(CurNumber) = Val(color) Or CurName = color Then 'color requested was found
                    MainProgram.MainFlash.SetVariable("colorprof.x" + LTrim(Str(x)) + "y" + LTrim(Str(y)) + "c", m_node.Attributes.GetNamedItem("color").Value)
                    Exit For
                End If
            Next
            Return 1
        Catch errorVariable As Exception
            MainProgram.SND("/RERROR: " + errorVariable.ToString())
            Return 0
        End Try
    End Function
#End Region
    Public Sub LoadSector(ByVal SectorVIRID As String, ByVal Display As Boolean, Optional ByVal ForceMapFullLoad As Boolean = False)
        Dim MapChanged As Boolean = False
        If GenerateMap.RandomMap = True Then
            If GenerateMap.MapCreated = False Then
                GenerateMap.BeginGeneration()
            End If
            Exit Sub 'random maps don't use preset resources
        End If
        Array.Clear(MainProgram.DialogueInvalid, 0, MainProgram.DialogueInvalid.Length)
        Array.Clear(MainProgram.DialogueConditioned, 0, MainProgram.DialogueConditioned.Length)
        If MainProgram.MapData = "" Then
            MainProgram.MapData = MainProgram.GetFileContents(MainProgram.DirMaps, MainProgram.sErr)
        End If
        If MainProgram.sErr = "" Then
            Dim CurrentMapDataPosition As Integer = 1
            Dim SectorFileLocation As Integer = InStr(MainProgram.MapData, "VIRID#" + SectorVIRID + "(")
            Dim Tempvar2 As Integer
            'MainProgram.SaveTheSector()
            If SectorVIRID <> MainProgram.MapData_VIRID And Display = True Then
                If SectorFileLocation > 0 Then
                    Dim DataSearchResult() As String
                    DataSearchResult = Recur2(CurrentMapDataPosition, "VIRID", SectorVIRID, False, True)
                    MainProgram.MapData_VIRID = DataSearchResult(0)
                    If DataSearchResult(0) <> "ERROR" Or DataSearchResult(1) <> "-1" Then CurrentMapDataPosition = Val(DataSearchResult(1))
                    DataSearchResult = Recur2(CurrentMapDataPosition, "SAFER", SectorVIRID, False, True, "0")
                    MainProgram.MapData_SafeRoom = DataSearchResult(0)
                    SectorFileLocation = InStr(CurrentMapDataPosition, MainProgram.MapData, "PARID#" + SectorVIRID + "(")
                    For Tempvar2 = SectorFileLocation To Len(MainProgram.MapData) Step 1
                        If Mid(MainProgram.MapData, Tempvar2, 1) = ")" Then
                            MainProgram.MapData_PARID = Replace(Mid(MainProgram.MapData, SectorFileLocation + 7 + Len(LTrim(RTrim(SectorVIRID))), Tempvar2 - (SectorFileLocation + 7 + Len(LTrim(RTrim(SectorVIRID))))), " ", "")
                            Dim aint As Integer = Len(MainProgram.MapData_PARID) + 1
                            Dim bint As Integer
                            Dim dint As Integer = 0
                            Dim round As Integer
                            Dim astr As String
                            Dim bstr As String = MainProgram.MapData_PARID + ""
                            For bint = 1 To aint + 1 Step 1
                                If Mid(bstr + ",", bint, 1) = "," Then
                                    round += 1
                                    astr = Mid(bstr, dint + 1, bint - dint - 1)
                                    dint = bint
                                    If round = 1 Then
                                        MainProgram.UserLocation_World = Val(astr)
                                    ElseIf round = 2 Then
                                        MainProgram.UserLocation_Continent = Val(astr)
                                    ElseIf round = 3 Then
                                        MainProgram.UserLocation_Province = Val(astr)
                                    ElseIf round = 4 Then
                                        MainProgram.UserLocation_Area = Val(astr)
                                    ElseIf round = 5 Then
                                        MainProgram.UserLocation_Map = Val(astr)
                                    ElseIf round = 6 Then
                                        MainProgram.UserLocation_Sector = Val(astr)
                                    ElseIf round = 7 Then
                                        MainProgram.UserLocation_Environ = Val(astr)
                                        DistributeEnvironmentVariables(Val(astr))
                                    ElseIf round = 8 Then
                                        MainProgram.UserLocation_Accessible = Val(astr)
                                    ElseIf round = 9 Then
                                        If Mid(astr, 1, 1) = "[" Then
                                            Dim Result() As String = Recur(astr)
                                            MainProgram.UserLocation_EastMap = Val(Result(0))
                                            MainProgram.UserLocation_EastCNCT = Val(Result(1))
                                        Else
                                            MainProgram.UserLocation_EastCNCT = Val(astr)
                                            MainProgram.UserLocation_EastMap = 0
                                        End If
                                    ElseIf round = 10 Then
                                        If Mid(astr, 1, 1) = "[" Then
                                            Dim Result() As String = Recur(astr)
                                            MainProgram.UserLocation_WestMap = Val(Result(0))
                                            MainProgram.UserLocation_WestCNCT = Val(Result(1))
                                        Else
                                            MainProgram.UserLocation_WestCNCT = Val(astr)
                                            MainProgram.UserLocation_WestMap = 0
                                        End If
                                    ElseIf round = 11 Then
                                        If Mid(astr, 1, 1) = "[" Then
                                            Dim Result() As String = Recur(astr)
                                            MainProgram.UserLocation_NorthMap = Val(Result(0))
                                            MainProgram.UserLocation_NorthCNCT = Val(Result(1))
                                        Else
                                            MainProgram.UserLocation_NorthCNCT = Val(astr)
                                            MainProgram.UserLocation_NorthMap = 0
                                        End If
                                    ElseIf round = 12 Then
                                        If Mid(astr, 1, 1) = "[" Then
                                            Dim Result() As String = Recur(astr)
                                            MainProgram.UserLocation_SouthMap = Val(Result(0))
                                            MainProgram.UserLocation_SouthCNCT = Val(Result(1))
                                        Else
                                            MainProgram.UserLocation_SouthCNCT = Val(astr)
                                            MainProgram.UserLocation_SouthMap = 0
                                        End If
                                    ElseIf round = 13 Then
                                        If Mid(astr, 1, 1) = "[" Then
                                            Dim Result() As String = Recur(astr)
                                            MainProgram.UserLocation_UpMap = Val(Result(0))
                                            MainProgram.UserLocation_UpCNCT = Val(Result(1))
                                        Else
                                            MainProgram.UserLocation_UpCNCT = Val(astr)
                                            MainProgram.UserLocation_UpMap = 0
                                        End If
                                    ElseIf round = 14 Then
                                        If Mid(astr, 1, 1) = "[" Then
                                            Dim Result() As String = Recur(astr)
                                            MainProgram.UserLocation_DownMap = Val(Result(0))
                                            MainProgram.UserLocation_DownCNCT = Val(Result(1))
                                        Else
                                            MainProgram.UserLocation_DownCNCT = Val(astr)
                                            MainProgram.UserLocation_DownMap = 0
                                        End If
                                    End If
                                End If
                            Next
                            Exit For
                        End If
                    Next
                    'Load the map header if it's not already loaded. If there are no errors then find the world, continent, province, area, map, and current sector
                    'note that it doesn't start at the top of the document but starts at where it last left off so this reads the same variable no more than once and 
                    'curses all the way to the bottom respecfully. RECUR2 function is used to clean this code up since it's all similar functions.
                    If MainProgram.MapHeaderData = "" Then MainProgram.MapHeaderData = MainProgram.GetFileContents(MainProgram.DirMapHeader, MainProgram.sErr)
                    If MainProgram.sErr = "" Then
                        Dim CurrentMapHeaderPosition As Integer = 1, ReturnValue As String()
                        ReturnValue = Recur2(CurrentMapHeaderPosition, "WORLD", LTrim(Str(MainProgram.UserLocation_World)))
                        MainProgram.UserLocation_WorldString = ReturnValue(0)
                        CurrentMapHeaderPosition = Val(ReturnValue(1))
                        ReturnValue = Recur2(CurrentMapHeaderPosition, "CONTINENT", LTrim(Str(MainProgram.UserLocation_Continent)), True)
                        MainProgram.UserLocation_ContinentString = ReturnValue(0)
                        CurrentMapHeaderPosition = Val(ReturnValue(1))
                        ReturnValue = Recur2(CurrentMapHeaderPosition, "PROVINCE", LTrim(Str(MainProgram.UserLocation_Province)), True)
                        MainProgram.UserLocation_ProvinceString = ReturnValue(0)
                        CurrentMapHeaderPosition = Val(ReturnValue(1))
                        ReturnValue = Recur2(CurrentMapHeaderPosition, "AREA", LTrim(Str(MainProgram.UserLocation_Area)), True)
                        MainProgram.UserLocation_AreaString = ReturnValue(0)
                        CurrentMapHeaderPosition = Val(ReturnValue(1))
                        ReturnValue = Recur2(CurrentMapHeaderPosition, "MAP", LTrim(Str(MainProgram.UserLocation_Map)), True)
                        If InitialMap <> ReturnValue(0) Then MapChanged = True
                        MainProgram.UserLocation_MapString = ReturnValue(0)
                        CurrentMapHeaderPosition = Val(ReturnValue(1))
                        ReturnValue = Recur2(CurrentMapHeaderPosition, "SECTOR", LTrim(Str(MainProgram.UserLocation_Sector)), True)
                        MainProgram.UserLocation_SectorString = ReturnValue(0)
                        CurrentMapHeaderPosition = Val(ReturnValue(1))
                    Else
                        Debug.WriteLine("Error retrieving file: " & MainProgram.sErr)
                    End If
                    DataSearchResult = Recur2(CurrentMapDataPosition, "SECTD", SectorVIRID, False, True, "You are here.")
                    MainProgram.MapData_SECTD = DataSearchResult(0)
                    If DataSearchResult(0) <> "ERROR" Or DataSearchResult(1) <> "-1" Then CurrentMapDataPosition = Val(DataSearchResult(1))
                    DataSearchResult = Recur2(CurrentMapDataPosition, "CCHAR", SectorVIRID, False, True)
                    MainProgram.MapData_CCHAR = DataSearchResult(0)
                    If DataSearchResult(0) <> "ERROR" Or DataSearchResult(1) <> "-1" Then CurrentMapDataPosition = Val(DataSearchResult(1))
                    DataSearchResult = Recur2(CurrentMapDataPosition, "DIAL1", SectorVIRID, False, True)
                    MainProgram.Dialogue(0) = DataSearchResult(0)
                    If DataSearchResult(0) <> "ERROR" Or DataSearchResult(1) <> "-1" Then CurrentMapDataPosition = Val(DataSearchResult(1))
                    DataSearchResult = Recur2(CurrentMapDataPosition, "DIAL2", SectorVIRID, False, True)
                    MainProgram.Dialogue(1) = DataSearchResult(0)
                    If DataSearchResult(0) <> "ERROR" Or DataSearchResult(1) <> "-1" Then CurrentMapDataPosition = Val(DataSearchResult(1))
                    DataSearchResult = Recur2(CurrentMapDataPosition, "DIAL3", SectorVIRID, False, True)
                    MainProgram.Dialogue(2) = DataSearchResult(0)
                    If DataSearchResult(0) <> "ERROR" Or DataSearchResult(1) <> "-1" Then CurrentMapDataPosition = Val(DataSearchResult(1))
                    DataSearchResult = Recur2(CurrentMapDataPosition, "DIAL4", SectorVIRID, False, True)
                    MainProgram.Dialogue(3) = DataSearchResult(0)
                    If DataSearchResult(0) <> "ERROR" Or DataSearchResult(1) <> "-1" Then CurrentMapDataPosition = Val(DataSearchResult(1))
                    DataSearchResult = Recur2(CurrentMapDataPosition, "DIAL5", SectorVIRID, False, True)
                    MainProgram.Dialogue(4) = DataSearchResult(0)
                    If DataSearchResult(0) <> "ERROR" Or DataSearchResult(1) <> "-1" Then CurrentMapDataPosition = Val(DataSearchResult(1))
                    DataSearchResult = Recur2(CurrentMapDataPosition, "DIAL6", SectorVIRID, False, True)
                    MainProgram.Dialogue(5) = DataSearchResult(0)
                    If DataSearchResult(0) <> "ERROR" Or DataSearchResult(1) <> "-1" Then CurrentMapDataPosition = Val(DataSearchResult(1))
                    DataSearchResult = Recur2(CurrentMapDataPosition, "DIAL7", SectorVIRID, False, True)
                    MainProgram.Dialogue(6) = DataSearchResult(0)
                    If DataSearchResult(0) <> "ERROR" Or DataSearchResult(1) <> "-1" Then CurrentMapDataPosition = Val(DataSearchResult(1))
                    DataSearchResult = Recur2(CurrentMapDataPosition, "DIAL8", SectorVIRID, False, True)
                    MainProgram.Dialogue(7) = DataSearchResult(0)
                    If DataSearchResult(0) <> "ERROR" Or DataSearchResult(1) <> "-1" Then CurrentMapDataPosition = Val(DataSearchResult(1))
                    DataSearchResult = Recur2(CurrentMapDataPosition, "DIAL9", SectorVIRID, False, True)
                    MainProgram.Dialogue(8) = DataSearchResult(0)
                    If DataSearchResult(0) <> "ERROR" Or DataSearchResult(1) <> "-1" Then CurrentMapDataPosition = Val(DataSearchResult(1))
                    DataSearchResult = Recur2(CurrentMapDataPosition, "DRTEM", SectorVIRID, False, True)
                    MainProgram.MapData_DRTEM = DataSearchResult(0)
                    If DataSearchResult(0) <> "ERROR" Or DataSearchResult(1) <> "-1" Then CurrentMapDataPosition = Val(DataSearchResult(1))
                End If
            Else
                Dim DataSearchResult() As String
                DataSearchResult = Recur2(CurrentMapDataPosition, "CCHAR", SectorVIRID, False, True)
                MainProgram.MapData_CCHAR = DataSearchResult(0)
                If DataSearchResult(0) <> "ERROR" Or DataSearchResult(1) <> "-1" Then CurrentMapDataPosition = Val(DataSearchResult(1))
            End If
            If MainProgram.MapData_CCHAR <> "" Then
                MainProgram.User_CurRoom = 0
                For SectorFileLocation = 1 To Len(MainProgram.MapData_CCHAR) + 1 Step 1
                    If Mid(MainProgram.MapData_CCHAR + ",", SectorFileLocation, 1) = "," Then
                        MainProgram.User_CurRoom += 1
                    End If
                Next
            Else
                MainProgram.User_CurRoom = 0
            End If
            If ForceMapFullLoad = True Then MapChanged = True 'this forces the entire map to be redrawn, is forced when switching from a random map to a regular map
            If Display = True Then
                Dim tempstr As String = ""
                Dim tempstr2 As String = ""
                MainProgram.MapData_CurrentMobs = ""
                MainProgram.MapData_CurrentProps = ""
                Array.ForEach(MainProgram.DialogueProgress, AddressOf DecreaseByOne)
                Array.Clear(MainProgram.DialogueText, 0, MainProgram.DialogueText.Length)
                'weather per map
                If MapChanged = True Then
                    'Distinguish sector weather.
                    Dim RndWeather As New Random
                    Dim tmp As Integer, tmp2 As Integer
                    Dim tmp1 As String, TheSeason As String = ""
                    Dim count As Integer = 0
                    MainProgram.MapData_CurWeather = ""
                    MainProgram.MapData_EnvironWeather = LTrim(Str(Val(MainProgram.MapData_EnvironWeather)))
                    While MainProgram.MapData_CurWeather = ""
                        tmp = RndWeather.Next(0, 23)
                        tmp1 = MainProgram.MapData_EnvironWeather
                        If MainProgram.MapData_EnvironWeather = "0" Then
                            MainProgram.MapData_CurWeather = "None"
                            Exit While
                        End If
                        If InStr(MainProgram.MapData_EnvironWeather, LTrim(Str(tmp)) + ",") Then
                            If tmp = 0 Then
                                If Mid(MainProgram.MapData_EnvironWeather, 1, 2) <> "0," Then
                                    tmp = -1
                                End If
                            ElseIf tmp = 1 Then
                                If Mid(MainProgram.MapData_EnvironWeather, 1, 2) <> "1," Then
                                    tmp = -1
                                End If
                            End If
                            count += 1
                            If count = 50 Then
                                MainProgram.MapData_CurWeather = "None"
                            End If
                            'next if block checks appropriate weather patterns for perspective season
                            If MainProgram.Serverdatemonth = "Turn of Ritkus" Then 'Spring
                                TheSeason = "Spring"
                            ElseIf MainProgram.Serverdatemonth = "Lythantos' Breath" Then 'Spring
                                TheSeason = "Spring"
                            ElseIf MainProgram.Serverdatemonth = "The Shaded Aveo" Then 'Summer
                                TheSeason = "Summer"
                            ElseIf MainProgram.Serverdatemonth = "The Burning Oeva" Then 'Summer
                                TheSeason = "Summer"
                            ElseIf MainProgram.Serverdatemonth = "The Dying Flower" Then 'Fall
                                TheSeason = "Fall"
                            ElseIf MainProgram.Serverdatemonth = "Roahn's Becoming" Then 'Fall
                                TheSeason = "Fall"
                            ElseIf MainProgram.Serverdatemonth = "Falling Leaf" Then 'Fall
                                TheSeason = "Fall"
                            ElseIf MainProgram.Serverdatemonth = "Winterblight" Then 'Winter
                                TheSeason = "Winter"
                            ElseIf MainProgram.Serverdatemonth = "Changing Tide" Then 'Winter
                                TheSeason = "Winter"
                            ElseIf MainProgram.Serverdatemonth = "Mahro's Blessing" Then 'Spring
                                TheSeason = "Spring"
                            ElseIf MainProgram.Serverdatemonth = "Ettphemones Return" Then 'Spring
                                TheSeason = "Spring"
                            End If
                            If TheSeason = "Spring" Then
                                If tmp = 6 Then
                                    tmp = -1
                                ElseIf tmp = 8 Then
                                    tmp = -1
                                ElseIf tmp = 9 Then
                                    tmp = -1
                                ElseIf tmp = 16 Then
                                    tmp = -1
                                End If
                            ElseIf TheSeason = "Summer" Then
                                If tmp = 6 Then
                                    tmp = -1
                                ElseIf tmp = 7 Then
                                    tmp = -1
                                ElseIf tmp = 8 Then
                                    tmp = -1
                                ElseIf tmp = 9 Then
                                    tmp = -1
                                ElseIf tmp = 12 Then
                                    tmp = -1
                                ElseIf tmp = 16 Then
                                    tmp = -1
                                End If
                            ElseIf TheSeason = "Fall" Then
                                If tmp = 8 Then
                                    tmp = -1
                                ElseIf tmp = 9 Then
                                    tmp = -1

                                ElseIf tmp = 16 Then
                                    tmp = -1
                                End If
                            ElseIf TheSeason = "Winter" Then
                                If tmp = 3 Then
                                    tmp = -1
                                ElseIf tmp = 10 Then
                                    tmp = -1
                                ElseIf tmp = 11 Then
                                    tmp = -1
                                ElseIf tmp = 17 Then
                                    tmp = -1
                                ElseIf tmp = 18 Then
                                    tmp = -1
                                End If
                            End If
                            'next if block is for testing severe weather types if season mark-up succeeded
                            If tmp = 11 Then 'Thunderstorm checking chances for success
                                tmp2 = RndWeather.Next(1, 1000)
                                If tmp2 < 1000 - 420 Then
                                    tmp = -1
                                End If
                            ElseIf tmp = 12 Then 'Graupel checking chances for success
                                tmp2 = RndWeather.Next(1, 1000)
                                If tmp2 < 1000 - 41 Then
                                    tmp = -1
                                End If
                            ElseIf tmp = 13 Then 'Ice pellets checking chances for success
                                tmp2 = RndWeather.Next(1, 1000)
                                If tmp2 < 1000 - 80 Then
                                    tmp = -1
                                End If
                            ElseIf tmp = 14 Then 'Hail checking chances for success
                                tmp2 = RndWeather.Next(1, 1000)
                                If tmp2 < 1000 - 50 Then
                                    tmp = -1
                                End If
                            ElseIf tmp = 15 Then 'Monsoon checking chances for success
                                tmp2 = RndWeather.Next(1, 1000)
                                If tmp2 < 1000 - 120 Then
                                    tmp = -1
                                End If
                            ElseIf tmp = 16 Then 'Blizzard checking chances for success
                                tmp2 = RndWeather.Next(1, 1000)
                                If tmp2 < 1000 - 75 Then
                                    tmp = -1
                                End If
                            ElseIf tmp = 17 Then 'Tornado checking chances for success
                                tmp2 = RndWeather.Next(1, 1000)
                                If tmp2 < 1000 - 33 Then
                                    tmp = -1
                                End If
                            ElseIf tmp = 18 Then 'Hurricane checking chances for success
                                tmp2 = RndWeather.Next(1, 1000)
                                If tmp2 < 1000 - 210 Then
                                    tmp = -1
                                End If
                            ElseIf tmp = 19 Then 'Acid Rain checking chances for success
                                tmp2 = RndWeather.Next(1, 1000)
                                If tmp2 < 1000 - 420 Then
                                    tmp = -1
                                End If
                            ElseIf tmp = 20 Then 'Haze checking chances for success
                                tmp2 = RndWeather.Next(1, 1000)
                                If tmp2 < 1000 - 480 Then
                                    tmp = -1
                                End If
                            ElseIf tmp = 21 Then 'Fog checking chances for success
                                tmp2 = RndWeather.Next(1, 1000)
                                If tmp2 < 1000 - 500 Then
                                    tmp = -1
                                End If
                            End If
                            If tmp = 0 Then
                                MainProgram.MapData_CurWeather = "None"
                            ElseIf tmp = 1 Then
                                MainProgram.MapData_CurWeather = "Cloudy"
                                If MainProgram.MapData_EnvironMagic = "0" Then
                                    MainProgram.MapData_EnvironMagic = "F +0.2"
                                Else
                                    If InStr(MainProgram.MapData_EnvironMagic, "F +") Then
                                        tmp1 = Replace(MainProgram.MapData_EnvironMagic, "F +", "")
                                        MainProgram.MapData_EnvironMagic = "F +" + LTrim(Str(Val(tmp1) + 0.5))
                                    Else
                                        MainProgram.MapData_EnvironMagic += ",F +0.2"
                                    End If
                                End If
                            ElseIf tmp = 2 Then
                                MainProgram.MapData_CurWeather = "Partly Cloudy"
                                If MainProgram.MapData_EnvironMagic = "0" Then
                                    MainProgram.MapData_EnvironMagic = "F +0.5"
                                Else
                                    If InStr(MainProgram.MapData_EnvironMagic, "F +") Then
                                        tmp1 = Replace(MainProgram.MapData_EnvironMagic, "F +", "")
                                        MainProgram.MapData_EnvironMagic = "F +" + LTrim(Str(Val(tmp1) + 0.5))
                                    Else
                                        MainProgram.MapData_EnvironMagic += ",F +0.5"
                                    End If
                                End If
                            ElseIf tmp = 3 Then
                                MainProgram.MapData_CurWeather = "Sunny"
                                If MainProgram.MapData_EnvironMagic = "0" Then
                                    MainProgram.MapData_EnvironMagic = "F +0.7"
                                Else
                                    If InStr(MainProgram.MapData_EnvironMagic, "F +") Then
                                        tmp1 = Replace(MainProgram.MapData_EnvironMagic, "F +", "")
                                        MainProgram.MapData_EnvironMagic = "F +" + LTrim(Str(Val(tmp1) + 0.5))
                                    Else
                                        MainProgram.MapData_EnvironMagic += ",F +0.7"
                                    End If
                                End If
                            ElseIf tmp = 4 Then
                                MainProgram.MapData_CurWeather = "Mist"
                                If MainProgram.MapData_EnvironMagic = "0" Then
                                    MainProgram.MapData_EnvironMagic = "W +0.1"
                                Else
                                    If InStr(MainProgram.MapData_EnvironMagic, "W +") Then
                                        tmp1 = Replace(MainProgram.MapData_EnvironMagic, "W +", "")
                                        MainProgram.MapData_EnvironMagic = "W +" + LTrim(Str(Val(tmp1) + 0.5))
                                    Else
                                        MainProgram.MapData_EnvironMagic += ",W +0.1"
                                    End If
                                End If
                            ElseIf tmp = 5 Then
                                MainProgram.MapData_CurWeather = "Drizzle"
                                If MainProgram.MapData_EnvironMagic = "0" Then
                                    MainProgram.MapData_EnvironMagic = "W +0.2"
                                Else
                                    If InStr(MainProgram.MapData_EnvironMagic, "W +") Then
                                        tmp1 = Replace(MainProgram.MapData_EnvironMagic, "W +", "")
                                        MainProgram.MapData_EnvironMagic = "W +" + LTrim(Str(Val(tmp1) + 0.5))
                                    Else
                                        MainProgram.MapData_EnvironMagic += ",W +0.2"
                                    End If
                                End If
                            ElseIf tmp = 6 Then
                                MainProgram.MapData_CurWeather = "Ice Storm"
                                If MainProgram.MapData_EnvironMagic = "0" Then
                                    MainProgram.MapData_EnvironMagic = "W +0.3"
                                Else
                                    If InStr(MainProgram.MapData_EnvironMagic, "W +") Then
                                        tmp1 = Replace(MainProgram.MapData_EnvironMagic, "W +", "")
                                        MainProgram.MapData_EnvironMagic = "W +" + LTrim(Str(Val(tmp1) + 0.5))
                                    Else
                                        MainProgram.MapData_EnvironMagic += ",W +0.3"
                                    End If
                                End If
                            ElseIf tmp = 7 Then
                                MainProgram.MapData_CurWeather = "Freezing Rain"
                                If MainProgram.MapData_EnvironMagic = "0" Then
                                    MainProgram.MapData_EnvironMagic = "W +0.5"
                                Else
                                    If InStr(MainProgram.MapData_EnvironMagic, "W +") Then
                                        tmp1 = Replace(MainProgram.MapData_EnvironMagic, "W +", "")
                                        MainProgram.MapData_EnvironMagic = "W +" + LTrim(Str(Val(tmp1) + 0.5))
                                    Else
                                        MainProgram.MapData_EnvironMagic += ",W +0.5"
                                    End If
                                End If
                            ElseIf tmp = 8 Then
                                MainProgram.MapData_CurWeather = "Snow"
                                If MainProgram.MapData_EnvironMagic = "0" Then
                                    MainProgram.MapData_EnvironMagic = "W +0.6"
                                Else
                                    If InStr(MainProgram.MapData_EnvironMagic, "W +") Then
                                        tmp1 = Replace(MainProgram.MapData_EnvironMagic, "W +", "")
                                        MainProgram.MapData_EnvironMagic = "W +" + LTrim(Str(Val(tmp1) + 0.5))
                                    Else
                                        MainProgram.MapData_EnvironMagic += ",W +0.6"
                                    End If
                                End If
                            ElseIf tmp = 9 Then
                                MainProgram.MapData_CurWeather = "Winter Storm"
                                If MainProgram.MapData_EnvironMagic = "0" Then
                                    MainProgram.MapData_EnvironMagic = "W +0.6"
                                Else
                                    If InStr(MainProgram.MapData_EnvironMagic, "W +") Then
                                        tmp1 = Replace(MainProgram.MapData_EnvironMagic, "W +", "")
                                        MainProgram.MapData_EnvironMagic = "W +" + LTrim(Str(Val(tmp1) + 0.5))
                                    Else
                                        MainProgram.MapData_EnvironMagic += ",W +0.6"
                                    End If
                                End If
                            ElseIf tmp = 10 Then
                                MainProgram.MapData_CurWeather = "Rainy"
                                If MainProgram.MapData_EnvironMagic = "0" Then
                                    MainProgram.MapData_EnvironMagic = "W +0.7"
                                Else
                                    If InStr(MainProgram.MapData_EnvironMagic, "W +") Then
                                        tmp1 = Replace(MainProgram.MapData_EnvironMagic, "W +", "")
                                        MainProgram.MapData_EnvironMagic = "W +" + LTrim(Str(Val(tmp1) + 0.5))
                                    Else
                                        MainProgram.MapData_EnvironMagic += ",W +0.7"
                                    End If
                                End If
                            ElseIf tmp = 11 Then
                                MainProgram.MapData_CurWeather = "Thunderstorm"
                                If MainProgram.MapData_EnvironMagic = "0" Then
                                    MainProgram.MapData_EnvironMagic = "W +0.7"
                                Else
                                    If InStr(MainProgram.MapData_EnvironMagic, "W +") Then
                                        tmp1 = Replace(MainProgram.MapData_EnvironMagic, "W +", "")
                                        MainProgram.MapData_EnvironMagic = "W +" + LTrim(Str(Val(tmp1) + 0.5))
                                    Else
                                        MainProgram.MapData_EnvironMagic += ",W +0.7"
                                    End If
                                End If
                            ElseIf tmp = 12 Then
                                MainProgram.MapData_CurWeather = "Graupel"
                                If MainProgram.MapData_EnvironMagic = "0" Then
                                    MainProgram.MapData_EnvironMagic = "E +0.2"
                                Else
                                    If InStr(MainProgram.MapData_EnvironMagic, "E +") Then
                                        tmp1 = Replace(MainProgram.MapData_EnvironMagic, "E +", "")
                                        MainProgram.MapData_EnvironMagic = "E +" + LTrim(Str(Val(tmp1) + 0.5))
                                    Else
                                        MainProgram.MapData_EnvironMagic += ",E +0.2"
                                    End If
                                End If
                            ElseIf tmp = 13 Then
                                MainProgram.MapData_CurWeather = "Ice Pellets"
                                If MainProgram.MapData_EnvironMagic = "0" Then
                                    MainProgram.MapData_EnvironMagic = "E +0.5"
                                Else
                                    If InStr(MainProgram.MapData_EnvironMagic, "E +") Then
                                        tmp1 = Replace(MainProgram.MapData_EnvironMagic, "E +", "")
                                        MainProgram.MapData_EnvironMagic = "E +" + LTrim(Str(Val(tmp1) + 0.5))
                                    Else
                                        MainProgram.MapData_EnvironMagic += ",E +0.5"
                                    End If
                                End If
                            ElseIf tmp = 14 Then
                                MainProgram.MapData_CurWeather = "Hail"
                                If MainProgram.MapData_EnvironMagic = "0" Then
                                    MainProgram.MapData_EnvironMagic = "E +0.7"
                                Else
                                    If InStr(MainProgram.MapData_EnvironMagic, "E +") Then
                                        tmp1 = Replace(MainProgram.MapData_EnvironMagic, "E +", "")
                                        MainProgram.MapData_EnvironMagic = "E +" + LTrim(Str(Val(tmp1) + 0.5))
                                    Else
                                        MainProgram.MapData_EnvironMagic += ",E +0.7"
                                    End If
                                End If
                            ElseIf tmp = 15 Then
                                MainProgram.MapData_CurWeather = "Monsoon"
                                If MainProgram.MapData_EnvironMagic = "0" Then
                                    MainProgram.MapData_EnvironMagic = "A +0.5"
                                Else
                                    If InStr(MainProgram.MapData_EnvironMagic, "A +") Then
                                        tmp1 = Replace(MainProgram.MapData_EnvironMagic, "A +", "")
                                        MainProgram.MapData_EnvironMagic = "A +" + LTrim(Str(Val(tmp1) + 0.5))
                                    Else
                                        MainProgram.MapData_EnvironMagic += ",A +0.5"
                                    End If
                                End If
                            ElseIf tmp = 16 Then
                                MainProgram.MapData_CurWeather = "Blizzard"
                                If MainProgram.MapData_EnvironMagic = "0" Then
                                    MainProgram.MapData_EnvironMagic = "A +1.0"
                                Else
                                    If InStr(MainProgram.MapData_EnvironMagic, "A +") Then
                                        tmp1 = Replace(MainProgram.MapData_EnvironMagic, "A +", "")
                                        MainProgram.MapData_EnvironMagic = "A +" + LTrim(Str(Val(tmp1) + 0.5))
                                    Else
                                        MainProgram.MapData_EnvironMagic += ",A +1.0"
                                    End If
                                End If
                            ElseIf tmp = 17 Then
                                MainProgram.MapData_CurWeather = "Tornado"
                                If MainProgram.MapData_EnvironMagic = "0" Then
                                    MainProgram.MapData_EnvironMagic = "A +1.5"
                                Else
                                    If InStr(MainProgram.MapData_EnvironMagic, "A +") Then
                                        tmp1 = Replace(MainProgram.MapData_EnvironMagic, "A +", "")
                                        MainProgram.MapData_EnvironMagic = "A +" + LTrim(Str(Val(tmp1) + 0.5))
                                    Else
                                        MainProgram.MapData_EnvironMagic += ",A +1.5"
                                    End If
                                End If
                            ElseIf tmp = 18 Then
                                MainProgram.MapData_CurWeather = "Hurricane"
                                If MainProgram.MapData_EnvironMagic = "0" Then
                                    MainProgram.MapData_EnvironMagic = "A +1.5"
                                Else
                                    If InStr(MainProgram.MapData_EnvironMagic, "A +") Then
                                        tmp1 = Replace(MainProgram.MapData_EnvironMagic, "A +", "")
                                        MainProgram.MapData_EnvironMagic = "A +" + LTrim(Str(Val(tmp1) + 0.5))
                                    Else
                                        MainProgram.MapData_EnvironMagic += ",A +1.5"
                                    End If
                                End If
                            ElseIf tmp = 19 Then
                                MainProgram.MapData_CurWeather = "Acid Rain"
                                If MainProgram.MapData_EnvironMagic = "0" Then
                                    MainProgram.MapData_EnvironMagic = "S +0.2"
                                Else
                                    If InStr(MainProgram.MapData_EnvironMagic, "S +") Then
                                        tmp1 = Replace(MainProgram.MapData_EnvironMagic, "S +", "")
                                        MainProgram.MapData_EnvironMagic = "S +" + LTrim(Str(Val(tmp1) + 0.5))
                                    Else
                                        MainProgram.MapData_EnvironMagic += ",S +0.2"
                                    End If
                                End If
                            ElseIf tmp = 20 Then
                                MainProgram.MapData_CurWeather = "Haze"
                                If MainProgram.MapData_EnvironMagic = "0" Then
                                    MainProgram.MapData_EnvironMagic = "S +1.0"
                                Else
                                    If InStr(MainProgram.MapData_EnvironMagic, "S +") Then
                                        tmp1 = Replace(MainProgram.MapData_EnvironMagic, "S +", "")
                                        MainProgram.MapData_EnvironMagic = "S +" + LTrim(Str(Val(tmp1) + 0.5))
                                    Else
                                        MainProgram.MapData_EnvironMagic += ",S +1.0"
                                    End If
                                End If
                            ElseIf tmp = 21 Then
                                MainProgram.MapData_CurWeather = "Fog"
                                If MainProgram.MapData_EnvironMagic = "0" Then
                                    MainProgram.MapData_EnvironMagic = "S +2.0"
                                Else
                                    If InStr(MainProgram.MapData_EnvironMagic, "S +") Then
                                        tmp1 = Replace(MainProgram.MapData_EnvironMagic, "S +", "")
                                        MainProgram.MapData_EnvironMagic = "S +" + LTrim(Str(Val(tmp1) + 0.5))
                                    Else
                                        MainProgram.MapData_EnvironMagic += ",S +2.0"
                                    End If
                                End If
                            End If
                            If MainProgram.MapData_CurWeather <> "" Then
                                Exit While
                            End If
                        Else
                            MainProgram.SND("/RERROR: 33 - TMP Error (Weather)")
                        End If
                    End While
                    'Distinguish sector temperature based on weather, environment constants and temperature
                    Dim RndTemp As New Random
                    If MainProgram.MapData_CurWeather = "Ice Storm" Then 'forced to cold
                        MainProgram.MapData_CurTemperature = LTrim(Str(RndTemp.Next(30, 67))) + " °F"
                    ElseIf MainProgram.MapData_CurWeather = "Freezing Rain" Then 'forced to very cold
                        MainProgram.MapData_CurTemperature = LTrim(Str(RndTemp.Next(0, 29))) + " °F"
                    ElseIf MainProgram.MapData_CurWeather = "Snow" Then 'forced to cold
                        MainProgram.MapData_CurTemperature = LTrim(Str(RndTemp.Next(30, 67))) + " °F"
                    ElseIf MainProgram.MapData_CurWeather = "Winter Storm" Then 'forced to very cold
                        MainProgram.MapData_CurTemperature = LTrim(Str(RndTemp.Next(0, 29))) + " °F"
                    ElseIf MainProgram.MapData_CurWeather = "Ice Pellets" Then 'forced to cold
                        MainProgram.MapData_CurTemperature = LTrim(Str(RndTemp.Next(30, 67))) + " °F"
                    ElseIf MainProgram.MapData_CurWeather = "Hail" Then 'forced to cold
                        MainProgram.MapData_CurTemperature = LTrim(Str(RndTemp.Next(30, 67))) + " °F"
                    ElseIf MainProgram.MapData_CurWeather = "Monsoon" Then 'forced to warm
                        MainProgram.MapData_CurTemperature = LTrim(Str(RndTemp.Next(78, 88))) + " °F"
                    ElseIf MainProgram.MapData_CurWeather = "Blizzard" Then 'forced to cold
                        MainProgram.MapData_CurTemperature = LTrim(Str(RndTemp.Next(30, 67))) + " °F"
                    ElseIf MainProgram.MapData_CurWeather = "Tornado" Then 'forced to normal
                        MainProgram.MapData_CurTemperature = LTrim(Str(RndTemp.Next(68, 77))) + " °F"
                    ElseIf MainProgram.MapData_CurWeather = "Hurricane" Then 'forced to warm
                        MainProgram.MapData_CurTemperature = LTrim(Str(RndTemp.Next(78, 88))) + " °F"
                    ElseIf MainProgram.MapData_CurWeather = "Acid Rain" Then 'forced to hot
                        MainProgram.MapData_CurTemperature = LTrim(Str(RndTemp.Next(89, 104))) + " °F"
                    ElseIf MainProgram.MapData_CurWeather = "Haze" Then 'forced to normal
                        MainProgram.MapData_CurTemperature = LTrim(Str(RndTemp.Next(68, 77))) + " °F"
                    Else
                        If MainProgram.MapData_EnvironTemp = 1 Then
                            MainProgram.MapData_CurTemperature = LTrim(Str(RndTemp.Next(0, 29))) + " °F"
                        ElseIf MainProgram.MapData_EnvironTemp = 2 Then
                            MainProgram.MapData_CurTemperature = LTrim(Str(RndTemp.Next(30, 67))) + " °F"
                        ElseIf MainProgram.MapData_EnvironTemp = 3 Then
                            MainProgram.MapData_CurTemperature = LTrim(Str(RndTemp.Next(68, 77))) + " °F"
                        ElseIf MainProgram.MapData_EnvironTemp = 4 Then
                            MainProgram.MapData_CurTemperature = LTrim(Str(RndTemp.Next(78, 88))) + " °F"
                        ElseIf MainProgram.MapData_EnvironTemp = 5 Then
                            MainProgram.MapData_CurTemperature = LTrim(Str(RndTemp.Next(89, 104))) + " °F"
                        ElseIf MainProgram.MapData_EnvironTemp = 6 Then
                            MainProgram.MapData_CurTemperature = LTrim(Str(RndTemp.Next(105, 119))) + " °F"
                        ElseIf MainProgram.MapData_EnvironTemp = 0 Then 'standard temperature, same as 3
                            MainProgram.MapData_CurTemperature = LTrim(Str(RndTemp.Next(68, 77))) + " °F"
                        Else 'this should NEVER happen, just catch if it's out of bounds anyways and make it standard
                            MainProgram.MapData_CurTemperature = LTrim(Str(RndTemp.Next(68, 77))) + " °F"
                        End If
                    End If
                End If
                'sector drawing
                If MapChanged = True Then
                    MainProgram.MainFlash.SetVariable("sector.txta", MainProgram.SepByCapital(MainProgram.UserLocation_ProvinceString))
                    MainProgram.MainFlash.SetVariable("sector.txtb", MainProgram.SepByCapital(MainProgram.UserLocation_AreaString))
                    MainProgram.MainFlash.SetVariable("sector.txtc", MainProgram.SepByCapital(MainProgram.UserLocation_MapString))
                    MainProgram.MainFlash.SetVariable("sector.txtd", MainProgram.SepByCapital(MainProgram.UserLocation_SectorString))
                    If My.Computer.FileSystem.FileExists(Replace(MainProgram.DirMapHeader, "MapHeader", MainProgram.UserLocation_MapString)) = False Then
                        MainProgram.SND("/RERROR: Map File - " + MainProgram.UserLocation_MapString + ".TG - not found.")
                    Else
                        MainProgram.DirMapCur = Replace(MainProgram.DirMapHeader, "MapHeader", MainProgram.UserLocation_MapString)
                    End If
                    If MainProgram.DirMapCur <> "" Then
                        Dim tmp As Integer = 0, lin As Integer = 1
                        Dim count As Integer = 0
                        Dim laststart As Integer = 0
                        Dim value As String
                        If MainProgram.CurMapData = "" Then
                            MainProgram.CurMapData = MainProgram.GetFileContents(MainProgram.DirMapCur, MainProgram.sErr)
                        End If
                        For lin = 1 To 15 Step 1
                            count = 0
                            For tmp = InStr(MainProgram.CurMapData, "L" + LTrim(Str(lin)) + "(") + 2 + Len(LTrim(Str(lin))) To Len(MainProgram.CurMapData) Step 1
                                If count = 0 Then
                                    laststart = InStr(MainProgram.CurMapData, "L" + LTrim(Str(lin)) + "(") + 2 + Len(LTrim(Str(lin)))
                                End If
                                If Mid(MainProgram.CurMapData, tmp, 1) = "," Then
                                    count += 1
                                    value = Mid(MainProgram.CurMapData, laststart, tmp - laststart)
                                    If LTrim(value) = LTrim(Str(MainProgram.UserLocation_Sector)) Then
                                        MainProgram.LastMapDataPoS_x = LTrim(Str(count))
                                        MainProgram.LastMapDataPoS_y = LTrim(Str(lin))
                                        MainProgram.LastMapDataPoSEnviron(count, lin) = Mid(MainProgram.CurMapData, InStr(MainProgram.CurMapData, "O" + LTrim(Str(lin)) + "(") + Len(LTrim(Str(lin))) - 2 + count * 4, 3)
                                        SetEnvironmentColor(count, lin, "101")
                                    Else
                                        SetEnvironmentColor(count, lin, Mid(MainProgram.CurMapData, InStr(MainProgram.CurMapData, "O" + LTrim(Str(lin)) + "(") + Len(LTrim(Str(lin))) - 2 + count * 4, 3))
                                    End If
                                    laststart = tmp + 1
                                ElseIf Mid(MainProgram.CurMapData, tmp, 1) = ")" Then
                                    count += 1
                                    value = Mid(MainProgram.CurMapData, laststart, tmp - laststart)
                                    If LTrim(value) = LTrim(Str(MainProgram.UserLocation_Sector)) Then
                                        MainProgram.LastMapDataPoS_x = LTrim(Str(count))
                                        MainProgram.LastMapDataPoS_y = LTrim(Str(lin))
                                        MainProgram.LastMapDataPoSEnviron(count, lin) = Mid(MainProgram.CurMapData, InStr(MainProgram.CurMapData, "O" + LTrim(Str(lin)) + "(") + Len(LTrim(Str(lin))) - 2 + count * 4, 3)
                                        SetEnvironmentColor(count, lin, "101")
                                    Else
                                        SetEnvironmentColor(count, lin, Mid(MainProgram.CurMapData, InStr(MainProgram.CurMapData, "O" + LTrim(Str(lin)) + "(") + Len(LTrim(Str(lin))) - 2 + count * 4, 3))
                                    End If
                                    Exit For
                                End If
                            Next
                        Next
                    End If
                    'this refreshes and sets the map
                    MainProgram.MainFlash.TGotoFrame("colorsprite", 1)
                    'exit markers
                    Dim tmp1 As Integer = 0, lin1 As Integer = 1
                    Dim count1 As Integer = 0
                    Dim laststart1 As Integer = 0
                    Dim north As Boolean = False, south As Boolean = False, east As Boolean = False, west As Boolean = False, up As Boolean = False, down As Boolean = False
                    For lin1 = 1 To 15 Step 1
                        count1 = 0
                        For tmp1 = InStr(MainProgram.CurMapData, "X" + LTrim(Str(lin1)) + "(") + 2 + Len(LTrim(Str(lin1))) To Len(MainProgram.CurMapData) Step 1
                            If count1 = 0 Then
                                laststart1 = InStr(MainProgram.CurMapData, "X" + LTrim(Str(lin1)) + "(") + 2 + Len(LTrim(Str(lin1)))
                            End If
                            If Mid(MainProgram.CurMapData, tmp1, 1) = "," Then
                                count1 += 1
                                If north = True Then
                                    MainProgram.MainFlash.TSetProperty("connections.x" + LTrim(Str(count1)) + "y" + LTrim(Str(lin1)) + "n", 0, LTrim(Str(-20 + 16.2 * count1)))
                                    MainProgram.MainFlash.TSetProperty("connections.x" + LTrim(Str(count1)) + "y" + LTrim(Str(lin1)) + "n", 1, LTrim(Str(-18 + 16.515 * lin1)))
                                Else
                                    MainProgram.MainFlash.TSetProperty("connections.x" + LTrim(Str(count1)) + "y" + LTrim(Str(lin1)) + "n", 0, "-500")
                                    MainProgram.MainFlash.TSetProperty("connections.x" + LTrim(Str(count1)) + "y" + LTrim(Str(lin1)) + "n", 1, "-500")
                                End If
                                If south = True Then
                                    MainProgram.MainFlash.TSetProperty("connections.x" + LTrim(Str(count1)) + "y" + LTrim(Str(lin1)) + "s", 0, LTrim(Str(-20 + 16.2 * count1)))
                                    MainProgram.MainFlash.TSetProperty("connections.x" + LTrim(Str(count1)) + "y" + LTrim(Str(lin1)) + "s", 1, LTrim(Str(-10 + 16.515 * lin1)))
                                Else
                                    MainProgram.MainFlash.TSetProperty("connections.x" + LTrim(Str(count1)) + "y" + LTrim(Str(lin1)) + "s", 0, "-500")
                                    MainProgram.MainFlash.TSetProperty("connections.x" + LTrim(Str(count1)) + "y" + LTrim(Str(lin1)) + "s", 1, "-500")
                                End If
                                If east = True Then
                                    MainProgram.MainFlash.TSetProperty("connections.x" + LTrim(Str(count1)) + "y" + LTrim(Str(lin1)) + "e", 0, LTrim(Str(-12 + 16.2 * count1)))
                                    MainProgram.MainFlash.TSetProperty("connections.x" + LTrim(Str(count1)) + "y" + LTrim(Str(lin1)) + "e", 1, LTrim(Str(-18 + 16.515 * lin1)))
                                Else
                                    MainProgram.MainFlash.TSetProperty("connections.x" + LTrim(Str(count1)) + "y" + LTrim(Str(lin1)) + "e", 0, "-500")
                                    MainProgram.MainFlash.TSetProperty("connections.x" + LTrim(Str(count1)) + "y" + LTrim(Str(lin1)) + "e", 1, "-500")
                                End If
                                If west = True Then
                                    MainProgram.MainFlash.TSetProperty("connections.x" + LTrim(Str(count1)) + "y" + LTrim(Str(lin1)) + "w", 0, LTrim(Str(-20 + 16.2 * count1)))
                                    MainProgram.MainFlash.TSetProperty("connections.x" + LTrim(Str(count1)) + "y" + LTrim(Str(lin1)) + "w", 1, LTrim(Str(-18 + 16.515 * lin1)))
                                Else
                                    MainProgram.MainFlash.TSetProperty("connections.x" + LTrim(Str(count1)) + "y" + LTrim(Str(lin1)) + "w", 0, "-500")
                                    MainProgram.MainFlash.TSetProperty("connections.x" + LTrim(Str(count1)) + "y" + LTrim(Str(lin1)) + "w", 1, "-500")
                                End If
                                If up = True Then
                                    MainProgram.MainFlash.TSetProperty("connections.x" + LTrim(Str(count1)) + "y" + LTrim(Str(lin1)) + "u", 0, LTrim(Str(-20 + 16.2 * count1)))
                                    MainProgram.MainFlash.TSetProperty("connections.x" + LTrim(Str(count1)) + "y" + LTrim(Str(lin1)) + "u", 1, LTrim(Str(-18 + 16.515 * lin1)))
                                Else
                                    MainProgram.MainFlash.TSetProperty("connections.x" + LTrim(Str(count1)) + "y" + LTrim(Str(lin1)) + "u", 0, "-500")
                                    MainProgram.MainFlash.TSetProperty("connections.x" + LTrim(Str(count1)) + "y" + LTrim(Str(lin1)) + "u", 1, "-500")
                                End If
                                If down = True Then
                                    MainProgram.MainFlash.TSetProperty("connections.x" + LTrim(Str(count1)) + "y" + LTrim(Str(lin1)) + "d", 0, LTrim(Str(-20 + 16.2 * count1)))
                                    MainProgram.MainFlash.TSetProperty("connections.x" + LTrim(Str(count1)) + "y" + LTrim(Str(lin1)) + "d", 1, LTrim(Str(-18 + 16.515 * lin1)))
                                Else
                                    MainProgram.MainFlash.TSetProperty("connections.x" + LTrim(Str(count1)) + "y" + LTrim(Str(lin1)) + "d", 0, "-500")
                                    MainProgram.MainFlash.TSetProperty("connections.x" + LTrim(Str(count1)) + "y" + LTrim(Str(lin1)) + "d", 1, "-500")
                                End If
                                north = False : south = False : east = False
                                west = False : up = False : down = False
                                laststart1 = tmp1 + 1
                            ElseIf Mid(MainProgram.CurMapData, tmp1, 1) = ")" Then
                                count1 += 1
                                If north = True Then
                                    MainProgram.MainFlash.TSetProperty("connections.x" + LTrim(Str(count1)) + "y" + LTrim(Str(lin1)) + "n", 0, LTrim(Str(-20 + 16.2 * count1)))
                                    MainProgram.MainFlash.TSetProperty("connections.x" + LTrim(Str(count1)) + "y" + LTrim(Str(lin1)) + "n", 1, LTrim(Str(-18 + 16.515 * lin1)))
                                Else
                                    MainProgram.MainFlash.TSetProperty("connections.x" + LTrim(Str(count1)) + "y" + LTrim(Str(lin1)) + "n", 0, "-500")
                                    MainProgram.MainFlash.TSetProperty("connections.x" + LTrim(Str(count1)) + "y" + LTrim(Str(lin1)) + "n", 1, "-500")
                                End If
                                If south = True Then
                                    MainProgram.MainFlash.TSetProperty("connections.x" + LTrim(Str(count1)) + "y" + LTrim(Str(lin1)) + "s", 0, LTrim(Str(-20 + 16.2 * count1)))
                                    MainProgram.MainFlash.TSetProperty("connections.x" + LTrim(Str(count1)) + "y" + LTrim(Str(lin1)) + "s", 1, LTrim(Str(-10 + 16.515 * lin1)))
                                Else
                                    MainProgram.MainFlash.TSetProperty("connections.x" + LTrim(Str(count1)) + "y" + LTrim(Str(lin1)) + "s", 0, "-500")
                                    MainProgram.MainFlash.TSetProperty("connections.x" + LTrim(Str(count1)) + "y" + LTrim(Str(lin1)) + "s", 1, "-500")
                                End If
                                If east = True Then
                                    MainProgram.MainFlash.TSetProperty("connections.x" + LTrim(Str(count1)) + "y" + LTrim(Str(lin1)) + "e", 0, LTrim(Str(-12 + 16.2 * count1)))
                                    MainProgram.MainFlash.TSetProperty("connections.x" + LTrim(Str(count1)) + "y" + LTrim(Str(lin1)) + "e", 1, LTrim(Str(-18 + 16.515 * lin1)))
                                Else
                                    MainProgram.MainFlash.TSetProperty("connections.x" + LTrim(Str(count1)) + "y" + LTrim(Str(lin1)) + "e", 0, "-500")
                                    MainProgram.MainFlash.TSetProperty("connections.x" + LTrim(Str(count1)) + "y" + LTrim(Str(lin1)) + "e", 1, "-500")
                                End If
                                If west = True Then
                                    MainProgram.MainFlash.TSetProperty("connections.x" + LTrim(Str(count1)) + "y" + LTrim(Str(lin1)) + "w", 0, LTrim(Str(-20 + 16.2 * count1)))
                                    MainProgram.MainFlash.TSetProperty("connections.x" + LTrim(Str(count1)) + "y" + LTrim(Str(lin1)) + "w", 1, LTrim(Str(-18 + 16.515 * lin1)))
                                Else
                                    MainProgram.MainFlash.TSetProperty("connections.x" + LTrim(Str(count1)) + "y" + LTrim(Str(lin1)) + "w", 0, "-500")
                                    MainProgram.MainFlash.TSetProperty("connections.x" + LTrim(Str(count1)) + "y" + LTrim(Str(lin1)) + "w", 1, "-500")
                                End If
                                If up = True Then
                                    MainProgram.MainFlash.TSetProperty("connections.x" + LTrim(Str(count1)) + "y" + LTrim(Str(lin1)) + "u", 0, LTrim(Str(-20 + 16.2 * count1)))
                                    MainProgram.MainFlash.TSetProperty("connections.x" + LTrim(Str(count1)) + "y" + LTrim(Str(lin1)) + "u", 1, LTrim(Str(-18 + 16.515 * lin1)))
                                Else
                                    MainProgram.MainFlash.TSetProperty("connections.x" + LTrim(Str(count1)) + "y" + LTrim(Str(lin1)) + "u", 0, "-500")
                                    MainProgram.MainFlash.TSetProperty("connections.x" + LTrim(Str(count1)) + "y" + LTrim(Str(lin1)) + "u", 1, "-500")
                                End If
                                If down = True Then
                                    MainProgram.MainFlash.TSetProperty("connections.x" + LTrim(Str(count1)) + "y" + LTrim(Str(lin1)) + "d", 0, LTrim(Str(-20 + 16.2 * count1)))
                                    MainProgram.MainFlash.TSetProperty("connections.x" + LTrim(Str(count1)) + "y" + LTrim(Str(lin1)) + "d", 1, LTrim(Str(-18 + 16.515 * lin1)))
                                Else
                                    MainProgram.MainFlash.TSetProperty("connections.x" + LTrim(Str(count1)) + "y" + LTrim(Str(lin1)) + "d", 0, "-500")
                                    MainProgram.MainFlash.TSetProperty("connections.x" + LTrim(Str(count1)) + "y" + LTrim(Str(lin1)) + "d", 1, "-500")
                                End If
                                north = False : south = False : east = False
                                west = False : up = False : down = False
                                Exit For
                            ElseIf Mid(MainProgram.CurMapData, tmp1, 1) = "N" Then
                                north = True
                            ElseIf Mid(MainProgram.CurMapData, tmp1, 1) = "S" Then
                                south = True
                            ElseIf Mid(MainProgram.CurMapData, tmp1, 1) = "E" Then
                                east = True
                            ElseIf Mid(MainProgram.CurMapData, tmp1, 1) = "W" Then
                                west = True
                            ElseIf Mid(MainProgram.CurMapData, tmp1, 1) = "U" Then
                                up = True
                            ElseIf Mid(MainProgram.CurMapData, tmp1, 1) = "D" Then
                                down = True
                            End If
                        Next
                    Next
                    'end exit markers
                Else
                    'MainProgram.MainFlash.TGotoFrame(MainProgram.LastMapDataPoS, 3)
                    If MainProgram.LastMapDataPoSEnviron(Val(MainProgram.LastMapDataPoS_x), Val(MainProgram.LastMapDataPoS_y)) = "1" Then
                        MainProgram.MainFlash.TGotoFrame("x" + MainProgram.LastMapDataPoS_x + "y" + MainProgram.LastMapDataPoS_y, 1)
                    ElseIf MainProgram.LastMapDataPoSEnviron(Val(MainProgram.LastMapDataPoS_x), Val(MainProgram.LastMapDataPoS_y)) = "2" Then
                        MainProgram.MainFlash.TGotoFrame("x" + MainProgram.LastMapDataPoS_x + "y" + MainProgram.LastMapDataPoS_y, 0)
                    ElseIf MainProgram.LastMapDataPoSEnviron(Val(MainProgram.LastMapDataPoS_x), Val(MainProgram.LastMapDataPoS_y)) = "3" Then
                        MainProgram.MainFlash.TGotoFrame("x" + MainProgram.LastMapDataPoS_x + "y" + MainProgram.LastMapDataPoS_y, 3)
                    End If
                    MainProgram.MainFlash.SetVariable("sector.txta", MainProgram.SepByCapital(MainProgram.UserLocation_ProvinceString))
                    MainProgram.MainFlash.SetVariable("sector.txtb", MainProgram.SepByCapital(MainProgram.UserLocation_AreaString))
                    MainProgram.MainFlash.SetVariable("sector.txtc", MainProgram.SepByCapital(MainProgram.UserLocation_MapString))
                    MainProgram.MainFlash.SetVariable("sector.txtd", MainProgram.SepByCapital(MainProgram.UserLocation_SectorString))
                    Dim tmp As Integer = 0, lin As Integer = 1
                    Dim count As Integer = 0
                    Dim laststart As Integer = 0
                    Dim value As String
                    MainProgram.CurMapData = MainProgram.GetFileContents(MainProgram.DirMapCur, MainProgram.sErr)
                    For lin = 1 To 15 Step 1
                        count = 0
                        For tmp = InStr(MainProgram.CurMapData, "L" + LTrim(Str(lin)) + "(") + 2 + Len(LTrim(Str(lin))) To Len(MainProgram.CurMapData) Step 1
                            If count = 0 Then
                                laststart = InStr(MainProgram.CurMapData, "L" + LTrim(Str(lin)) + "(") + 2 + Len(LTrim(Str(lin)))
                            End If
                            If Mid(MainProgram.CurMapData, tmp, 1) = "," Then
                                count += 1
                                value = Mid(MainProgram.CurMapData, laststart, tmp - laststart)
                                If LTrim(value) = LTrim(Str(MainProgram.UserLocation_Sector)) Then
                                    MainProgram.LastMapDataPoS_x = LTrim(Str(count))
                                    MainProgram.LastMapDataPoS_y = LTrim(Str(lin))
                                    MainProgram.LastMapDataPoSEnviron(count, lin) = Mid(MainProgram.CurMapData, InStr(MainProgram.CurMapData, "O" + LTrim(Str(lin)) + "(") + Len(LTrim(Str(lin))) - 2 + count * 4, 3)
                                    SetEnvironmentColor(count, lin, "101")
                                Else
                                    SetEnvironmentColor(count, lin, Mid(MainProgram.CurMapData, InStr(MainProgram.CurMapData, "O" + LTrim(Str(lin)) + "(") + Len(LTrim(Str(lin))) - 2 + count * 4, 3))
                                End If
                                laststart = tmp + 1
                            ElseIf Mid(MainProgram.CurMapData, tmp, 1) = ")" Then
                                count += 1
                                value = Mid(MainProgram.CurMapData, laststart, tmp - laststart)
                                If LTrim(value) = LTrim(Str(MainProgram.UserLocation_Sector)) Then
                                    MainProgram.LastMapDataPoS_x = LTrim(Str(count))
                                    MainProgram.LastMapDataPoS_y = LTrim(Str(lin))
                                    MainProgram.LastMapDataPoSEnviron(count, lin) = Mid(MainProgram.CurMapData, InStr(MainProgram.CurMapData, "O" + LTrim(Str(lin)) + "(") + Len(LTrim(Str(lin))) - 2 + count * 4, 3)
                                    SetEnvironmentColor(count, lin, "101")
                                Else
                                    SetEnvironmentColor(count, lin, Mid(MainProgram.CurMapData, InStr(MainProgram.CurMapData, "O" + LTrim(Str(lin)) + "(") + Len(LTrim(Str(lin))) - 2 + count * 4, 3))
                                End If
                                Exit For
                            End If
                        Next
                    Next
                End If
                If MainProgram.MapData_SECTD <> "" Then
                    Dim tempp As String = "", saferoom As String = ""
                    If MainProgram.UserLocation_NorthCNCT <> 0 Then tempp += "/RN/r" Else tempp += "/rN"
                    If MainProgram.UserLocation_SouthCNCT <> 0 Then tempp += "/RS/r" Else tempp += "/rS"
                    If MainProgram.UserLocation_EastCNCT <> 0 Then tempp += "/RE/r" Else tempp += "/rE"
                    If MainProgram.UserLocation_WestCNCT <> 0 Then tempp += "/RW/r" Else tempp += "/rW"
                    If MainProgram.UserLocation_UpCNCT <> 0 Then tempp += "/RU/r" Else tempp += "/rU"
                    If MainProgram.UserLocation_DownCNCT <> 0 Then tempp += "/RD/r" Else tempp += "/rD"
                    If MainProgram.MapData_SafeRoom = "1" Then saferoom = "/WSafe Room"
                    MainProgram.SND("/zExits: /r[" + tempp + "] " + saferoom)
                    MainProgram.SND("/Z" + MainProgram.MapData_SECTD)
                    If MainProgram.MapData_CCHAR <> "" Then
                        MainProgram.User_CurRoom = 0
                        For SectorFileLocation = 1 To Len(MainProgram.MapData_CCHAR) + 1 Step 1
                            If Mid(MainProgram.MapData_CCHAR + ",", SectorFileLocation, 1) = "," Then
                                If Mid(MainProgram.MapData_CCHAR + ",", 1 + Len(tempstr2) + 1, 1) <> "." Then
                                    tempstr2 += ","
                                    Dim VNUM As String = Mid(MainProgram.MapData_CCHAR + ",", Len(tempstr2), 1)
                                    Dim tempx As Integer
                                    If Mid(MainProgram.MapData_CCHAR, Len(tempstr2), 1) <> "." Then
                                        For tempx = 1 + Len(tempstr2) To Len(MainProgram.MapData_CCHAR) Step 1
                                            If Mid(MainProgram.MapData_CCHAR, tempx, 1) = "." Then
                                                VNUM = Replace(Mid(MainProgram.MapData_CCHAR + ",", Len(tempstr2), tempx - Len(tempstr2)), ",", "")
                                                Exit For
                                            End If
                                        Next
                                    End If
                                    LoadMob(VNUM)
                                Else
                                    Dim VNUM As String = Mid(MainProgram.MapData_CCHAR + ",", 1 + Len(tempstr2), 1)
                                    Dim tempx As Integer
                                    If Mid(MainProgram.MapData_CCHAR, 2 + Len(tempstr2), 1) <> "." Then
                                        For tempx = 2 + Len(tempstr2) To Len(MainProgram.MapData_CCHAR) Step 1
                                            If Mid(MainProgram.MapData_CCHAR, tempx, 1) = "." Then
                                                VNUM = Replace(Mid(MainProgram.MapData_CCHAR + ",", 1 + Len(tempstr2), tempx - 2 - Len(tempstr2)), ",", "")
                                                Exit For
                                            End If
                                        Next
                                    End If
                                    LoadMob(VNUM)
                                End If
                                MainProgram.User_CurRoom += 1
                                Dim astring As String
                                astring = MainProgram.MapData_CCHAR
                                If InStr(Mid(MainProgram.MapData_CCHAR + ",", 1 + Len(tempstr2), SectorFileLocation - (Len(tempstr2) + 1)), "[") Then
                                    Dim astr As String = Mid(MainProgram.MapData_CCHAR + ",", 1 + Len(tempstr2), SectorFileLocation - (Len(tempstr2) + 1))
                                    Dim bstr As String
                                    Dim tmp0 As Integer
                                    Dim tmp1 As Integer = Len(astr)
                                    For tmp0 = 1 To tmp1 Step 1
                                        If Mid(astr, tmp0, 1) = "." Then
                                            bstr = Mid(astr, tmp0 + 1, tmp1 - tmp0)
                                            Dim t As Integer = Len(bstr)
                                            Dim t2 As Integer
                                            Dim u As Short
                                            Dim questflag As String = ""
                                            Dim mobtypeflag As String = ""
                                            Dim doublecheck As Boolean = True
                                            For t2 = 1 To t Step 1
                                                If Mid(bstr, t2, 1) = "[" Then
                                                    ShowEmote(Mid(bstr, 1, t2 - 1), 1, 1)
                                                End If
                                            Next
                                            If MainProgram.MobData_MobType = "Mini-Boss" Then
                                                mobtypeflag = " /W[/CMINI BOSS/W]"
                                            ElseIf MainProgram.MobData_MobType = "Boss" Then
                                                mobtypeflag = " /W[/RBOSS/W]"
                                            ElseIf MainProgram.MobData_MobType = "Rare" Then
                                                mobtypeflag = " /W[/YRARE/W]"
                                            ElseIf MainProgram.MobData_MobType = "Ultra Rare" Then
                                                mobtypeflag = " /W[/MULTRA RARE/W]"
                                            ElseIf MainProgram.MobData_MobType = "Epic" Then
                                                mobtypeflag = " /W[/GEPIC/W]"
                                            End If
                                            For u = 0 To 9 Step 1
                                                Dim tmp As String
                                                tmp = MainProgram.MobData_VIRID
                                                If MainProgram.User_questtarget(u) = MainProgram.MobData_VIRID And MainProgram.MobData_VIRID <> "" Then
                                                    questflag = "/R[TARGET]/w "
                                                    Exit For
                                                ElseIf MainProgram.User_questtaker(u) = MainProgram.MobData_VIRID And MainProgram.MobData_VIRID <> "" And MainProgram.User_questcomplete(u) = True Then
                                                    questflag = "/Y[!]/w "
                                                    Exit For
                                                ElseIf MainProgram.User_questtaker(u) = MainProgram.MobData_VIRID And MainProgram.MobData_VIRID <> "" And MainProgram.User_questcomplete(u) = False Then
                                                    questflag = "/z[!]/w "
                                                    Exit For
                                                ElseIf MainProgram.User_questgiver(u) = MainProgram.MobData_VIRID And MainProgram.MobData_VIRID <> "" And MainProgram.User_questcomplete(u) = False Then
                                                    questflag = "/z[?]/w "
                                                    Exit For
                                                ElseIf MainProgram.User_questgiver(u) = MainProgram.MobData_VIRID And MainProgram.MobData_VIRID <> "" And MainProgram.User_questcomplete(u) = True Then
                                                    questflag = "/w"
                                                    Exit For
                                                ElseIf MainProgram.MobData_HasQuest = True Then
                                                    questflag = "/Y[?]/w "
                                                    Exit For
                                                Else
                                                    questflag = "/w"
                                                End If
                                            Next
                                            MainProgram.SND(questflag + MainProgram.MobData_SHORT + " " + MainProgram.EmoteData_TARGD + " " + Replace(Mid(astr, InStr(astr, "[") + 1, Len(Mid(astr, tmp0 + 1, tmp1 - tmp0)) - InStr(astr, "[") + 2), "]", "") + "." + mobtypeflag)
                                            MainProgram.MapData_CurrentMobs += MainProgram.MobData_SHORT + "[" + MainProgram.MobData_VIRID + "]" + MainProgram.MobData_MNAME + "[" + MainProgram.MobData_VIRID + "]"
                                        End If
                                    Next
                                Else
                                    Dim astr As String = Mid(MainProgram.MapData_CCHAR + ",", 1 + Len(tempstr2), SectorFileLocation - (Len(tempstr2) + 1))
                                    Dim bstr As String
                                    Dim tmp0 As Integer
                                    Dim tmp1 As Integer = Len(astr)
                                    Dim questflag As String = ""
                                    Dim mobtypeflag As String = ""
                                    Dim doublecheck As Boolean = True
                                    Dim u As Short
                                    For tmp0 = 1 To tmp1 Step 1
                                        If Mid(astr, tmp0, 1) = "." Then
                                            bstr = Mid(astr, tmp0 + 1, tmp1 - tmp0)
                                            ShowEmote(bstr, 1, 1)
                                            If MainProgram.MobData_MobType = "Mini-Boss" Then
                                                mobtypeflag = " /W[/CMINI BOSS/W]"
                                            ElseIf MainProgram.MobData_MobType = "Boss" Then
                                                mobtypeflag = " /W[/RBOSS/W]"
                                            ElseIf MainProgram.MobData_MobType = "Rare" Then
                                                mobtypeflag = " /W[/YRARE/W]"
                                            ElseIf MainProgram.MobData_MobType = "Ultra Rare" Then
                                                mobtypeflag = " /W[/MULTRA RARE/W]"
                                            ElseIf MainProgram.MobData_MobType = "Epic" Then
                                                mobtypeflag = " /W[/GEPIC/W]"
                                            End If
                                            For u = 0 To 9 Step 1
                                                Dim tmp As String
                                                Dim tmp2 As String
                                                tmp = MainProgram.MobData_VIRID
                                                tmp2 = MainProgram.User_questtarget(u)
                                                If MainProgram.User_questtarget(u) = MainProgram.MobData_VIRID And MainProgram.MobData_VIRID <> "" Then
                                                    questflag = "/R[TARGET]/w "
                                                    Exit For
                                                ElseIf MainProgram.User_questtaker(u) = MainProgram.MobData_VIRID And MainProgram.MobData_VIRID <> "" And MainProgram.User_questcomplete(u) = True Then
                                                    questflag = "/Y[!]/w "
                                                    Exit For
                                                ElseIf MainProgram.User_questtaker(u) = MainProgram.MobData_VIRID And MainProgram.MobData_VIRID <> "" And MainProgram.User_questcomplete(u) = False Then
                                                    questflag = "/z[!]/w "
                                                    Exit For
                                                ElseIf MainProgram.User_questgiver(u) = MainProgram.MobData_VIRID And MainProgram.MobData_VIRID <> "" And MainProgram.User_questcomplete(u) = False Then
                                                    questflag = "/z[?]/w "
                                                    Exit For
                                                ElseIf MainProgram.User_questgiver(u) = MainProgram.MobData_VIRID And MainProgram.MobData_VIRID <> "" And MainProgram.User_questcomplete(u) = True Then
                                                    questflag = "/w"
                                                    Exit For
                                                ElseIf MainProgram.MobData_HasQuest = True Then
                                                    questflag = "/Y[?]/w "
                                                    Exit For
                                                Else
                                                    questflag = "/w"
                                                End If
                                            Next
                                            MainProgram.SND(questflag + MainProgram.MobData_SHORT + " " + MainProgram.EmoteData_PROPE + mobtypeflag)
                                            MainProgram.MapData_CurrentMobs += MainProgram.MobData_SHORT + "[" + MainProgram.MobData_VIRID + "]" + MainProgram.MobData_MNAME + "[" + MainProgram.MobData_VIRID + "]"
                                        End If
                                    Next
                                End If
                                If tempstr2 = "" Then
                                    tempstr2 = "" + Mid(MainProgram.MapData_CCHAR + ",", 1 + Len(tempstr2), SectorFileLocation - (Len(tempstr2) + 1))
                                Else
                                    tempstr2 += "" + Mid(MainProgram.MapData_CCHAR + ",", 1 + Len(tempstr2), SectorFileLocation - (Len(tempstr2) + 1))
                                End If
                            End If
                        Next
                        If MainProgram.MapData_STATC <> "" Then
                            Dim tmp0 As Integer, tmp1 As Integer, sint As Integer
                            Dim xstr As String = "," + MainProgram.MapData_STATC
                            For tmp0 = 1 To Len(xstr) Step 1
                                If Mid(xstr, tmp0, 1) = "," Then
                                    sint = tmp0 + 1
                                ElseIf Mid(xstr, tmp0, 1) = "." Then
                                    If Mid(xstr, sint, tmp0 - sint) = "?" Then
                                        For tmp1 = tmp0 To Len(xstr) Step 1
                                            If Mid(xstr, tmp1, 1) = "]" Then
                                                MainProgram.SND(Mid(xstr, sint + 3, tmp1 - sint - 3))
                                                tmp0 = tmp1
                                                Exit For
                                            End If
                                        Next
                                    Else
                                        LoadItem.LoadItem(Mid(xstr, sint, tmp0 - sint))
                                        MainProgram.SND(MainProgram.ItemData_LONGD)
                                        MainProgram.MapData_CurrentProps += MainProgram.ItemData_SHORT + "[" + MainProgram.ItemData_VIRID + "]" + MainProgram.ItemData_LONGD + "[" + MainProgram.MobData_VIRID + "]"
                                    End If
                                End If
                            Next
                            If MainProgram.MapData_DRTEM <> "" Then
                                xstr = MainProgram.MapData_DRTEM + ")"
                                tmp1 = Len(xstr)
                                For tmp0 = 1 To tmp1 Step 1
                                    If Mid(xstr, tmp0, 1) = "|" Then
                                        LoadItem.LoadItem(Mid(xstr, sint, tmp0 - sint))
                                        MainProgram.SND("/z" + MainProgram.ItemData_LONGD)
                                        MainProgram.MapData_CurrentProps += MainProgram.ItemData_SHORT + "[" + MainProgram.ItemData_VIRID + "]" + MainProgram.ItemData_LONGD + "[" + MainProgram.MobData_VIRID + "]"
                                    ElseIf Mid(xstr, tmp0, 1) = "," Then
                                        sint = tmp0 + 1
                                    ElseIf Mid(xstr, tmp0, 1) = ")" Then
                                        Exit For
                                    End If
                                Next
                            End If
                        Else
                            Dim tmp0 As Integer
                            Dim xstr As String = MainProgram.MapData_STATC + ")"
                            Dim tmp1 As Integer = Len(xstr)
                            Dim sint As Integer = 1
                            If MainProgram.MapData_DRTEM <> "" Then
                                xstr = MainProgram.MapData_DRTEM + ")"
                                tmp1 = Len(xstr)
                                For tmp0 = 1 To tmp1 Step 1
                                    If Mid(xstr, tmp0, 1) = "|" Then
                                        LoadItem.LoadItem(Mid(xstr, sint, tmp0 - sint))
                                        MainProgram.SND("/z" + MainProgram.ItemData_LONGD)
                                        MainProgram.MapData_CurrentProps += MainProgram.ItemData_SHORT + "[" + MainProgram.ItemData_VIRID + "]" + MainProgram.ItemData_LONGD + "[" + MainProgram.MobData_VIRID + "]"
                                    ElseIf Mid(xstr, tmp0, 1) = "," Then
                                        sint = tmp0 + 1
                                    ElseIf Mid(xstr, tmp0, 1) = ")" Then
                                        Exit For
                                    End If
                                Next
                            End If
                        End If
                    Else
                        MainProgram.User_CurRoom = 0
                        If MainProgram.MapData_STATC <> "" Then
                            Dim tmp0 As Integer, tmp1 As Integer, sint As Integer
                            Dim xstr As String = "," + MainProgram.MapData_STATC
                            For tmp0 = 1 To Len(xstr) Step 1
                                If Mid(xstr, tmp0, 1) = "," Then
                                    sint = tmp0 + 1
                                ElseIf Mid(xstr, tmp0, 1) = "." Then
                                    If Mid(xstr, sint, tmp0 - sint) = "?" Then
                                        For tmp1 = tmp0 To Len(xstr) Step 1
                                            If Mid(xstr, tmp1, 1) = "]" Then
                                                MainProgram.SND(Mid(xstr, sint + 3, tmp1 - sint - 3))
                                                tmp0 = tmp1
                                                Exit For
                                            End If
                                        Next
                                    Else
                                        LoadItem.LoadItem(Mid(xstr, sint, tmp0 - sint))
                                        MainProgram.SND(MainProgram.ItemData_LONGD)
                                        MainProgram.MapData_CurrentProps += MainProgram.ItemData_SHORT + "[" + MainProgram.ItemData_VIRID + "]" + MainProgram.ItemData_LONGD + "[" + MainProgram.MobData_VIRID + "]"
                                    End If
                                End If
                            Next
                            If MainProgram.MapData_DRTEM <> "" Then
                                xstr = MainProgram.MapData_DRTEM + ")"
                                tmp1 = Len(xstr)
                                For tmp0 = 1 To tmp1 Step 1
                                    If Mid(xstr, tmp0, 1) = "|" Then
                                        LoadItem.LoadItem(Mid(xstr, sint, tmp0 - sint))
                                        MainProgram.SND("/z" + MainProgram.ItemData_LONGD)
                                        MainProgram.MapData_CurrentProps += MainProgram.ItemData_SHORT + "[" + MainProgram.ItemData_VIRID + "]" + MainProgram.ItemData_LONGD + "[" + MainProgram.MobData_VIRID + "]"
                                    ElseIf Mid(xstr, tmp0, 1) = "," Then
                                        sint = tmp0 + 1
                                    ElseIf Mid(xstr, tmp0, 1) = ")" Then
                                        Exit For
                                    End If
                                Next
                            End If
                        Else
                            Dim tmp0 As Integer
                            Dim xstr As String = MainProgram.MapData_STATC + ")"
                            Dim tmp1 As Integer = Len(xstr)
                            Dim sint As Integer = 1
                            If MainProgram.MapData_DRTEM <> "" Then
                                xstr = MainProgram.MapData_DRTEM + ")"
                                tmp1 = Len(xstr)
                                For tmp0 = 1 To tmp1 Step 1
                                    If Mid(xstr, tmp0, 1) = "|" Then
                                        LoadItem.LoadItem(Mid(xstr, sint, tmp0 - sint))
                                        MainProgram.SND("/z" + MainProgram.ItemData_LONGD)
                                        MainProgram.MapData_CurrentProps += MainProgram.ItemData_SHORT + "[" + MainProgram.ItemData_VIRID + "]" + MainProgram.ItemData_LONGD + "[" + MainProgram.MobData_VIRID + "]"
                                    ElseIf Mid(xstr, tmp0, 1) = "," Then
                                        sint = tmp0 + 1
                                    ElseIf Mid(xstr, tmp0, 1) = ")" Then
                                        Exit For
                                    End If
                                Next
                            End If
                        End If
                    End If
                Else
                    MainProgram.SND("/RERROR! SECTOR " + MainProgram.MapData_VIRID + " DESCRIPTION IS NULL")
                End If
                ProcessLocation()
            Else
                If MainProgram.MapData_CCHAR <> "" Then
                    MainProgram.User_CurRoom = 0
                    For SectorFileLocation = 1 To Len(MainProgram.MapData_CCHAR) + 1 Step 1
                        If Mid(MainProgram.MapData_CCHAR + ",", SectorFileLocation, 1) = "," Then
                            MainProgram.User_CurRoom += 1
                        End If
                    Next
                Else
                    MainProgram.User_CurRoom = 0
                End If
            End If
        Else
            Debug.WriteLine("Error retrieving file: " & MainProgram.sErr)
        End If
    End Sub
    Private Sub ProcessLocation()
        If RandomMap = False Then
            Dim CURSCTR As String = MainProgram.MapData_VIRID
            Dim CURWEST As Short = MainProgram.UserLocation_WestCNCT
            Dim CURSOUTH As Short = MainProgram.UserLocation_SouthCNCT
            Dim CURNORTH As Short = MainProgram.UserLocation_NorthCNCT
            Dim CUREAST As Short = MainProgram.UserLocation_EastCNCT
            Dim CURUP As Short = MainProgram.UserLocation_UpCNCT
            Dim CURDOWN As Short = MainProgram.UserLocation_DownCNCT
            If CURNORTH <> 0 Then
                MainProgram.MainFlash.TGotoFrame("North", 0)
                LoadSector(LTrim(Str(CURNORTH)), 0)
                MainProgram.MainFlash.SetVariable("North.Northnum", LTrim(Str(MainProgram.User_CurRoom)))
            Else
                MainProgram.MainFlash.TGotoFrame("North", 2)
            End If
            If CUREAST <> 0 Then
                MainProgram.MainFlash.TGotoFrame("East", 0)
                LoadSector(LTrim(Str(CUREAST)), 0)
                MainProgram.MainFlash.SetVariable("East.Eastnum", LTrim(Str(MainProgram.User_CurRoom)))
            Else
                MainProgram.MainFlash.TGotoFrame("East", 2)
            End If
            If CURWEST <> 0 Then
                MainProgram.MainFlash.TGotoFrame("West", 0)
                LoadSector(LTrim(Str(CURWEST)), 0)
                MainProgram.MainFlash.SetVariable("West.Westnum", LTrim(Str(MainProgram.User_CurRoom)))
            Else
                MainProgram.MainFlash.TGotoFrame("West", 2)
            End If
            If CURDOWN <> 0 Then
                MainProgram.MainFlash.TGotoFrame("Down", 0)
                LoadSector(LTrim(Str(CURDOWN)), 0)
                MainProgram.MainFlash.SetVariable("Down.Downnum", LTrim(Str(MainProgram.User_CurRoom)))
            Else
                MainProgram.MainFlash.TGotoFrame("Down", 2)
            End If
            If CURUP <> 0 Then
                MainProgram.MainFlash.TGotoFrame("Up", 0)
                LoadSector(LTrim(Str(CURUP)), 0)
                MainProgram.MainFlash.SetVariable("Up.Upnum", LTrim(Str(MainProgram.User_CurRoom)))
            Else
                MainProgram.MainFlash.TGotoFrame("Up", 2)
            End If
            If CURSOUTH <> 0 Then
                MainProgram.MainFlash.TGotoFrame("South", 0)
                LoadSector(LTrim(Str(CURSOUTH)), 0)
                MainProgram.MainFlash.SetVariable("South.Southnum", LTrim(Str(MainProgram.User_CurRoom)))
            Else
                MainProgram.MainFlash.TGotoFrame("South", 2)
            End If
            LoadSector(CURSCTR, 0)
            MainProgram.MainFlash.SetVariable("Cur.Curnum", LTrim(Str(MainProgram.User_CurRoom + 1)))
        Else
            LoadSector("random", False)
        End If
    End Sub
    Public Sub SaveTheSector()
        Dim str1 As String
        Dim int2 As Integer
        Dim int3 As Integer
        str1 = MainProgram.MapData_VIRID
        int2 = InStr(MainProgram.MapData, "SECTD#" + str1 + "(")
        If InStr(MainProgram.MapData, "SECTD#" + str1 + "(") > 0 Then
            For int3 = int2 To Len(MainProgram.MapData) Step 1
                If Mid(MainProgram.MapData, int3, 1) = ")" Then
                    MainProgram.MapData = Mid(MainProgram.MapData, 1, int2 + 6 + Len(str1)) + MainProgram.MapData_SECTD + Mid(MainProgram.MapData, int3, MainProgram.MapData.Length)
                    Exit For
                End If
            Next
            int2 = InStr(MainProgram.MapData, "PARID#" + str1 + "(")
            If int2 > 0 Then
                For int3 = int2 To Len(MainProgram.MapData) Step 1
                    If Mid(MainProgram.MapData, int3, 1) = ")" Then
                        Dim tempb As String
                        If MainProgram.UserLocation_Accessible = "1" Then tempb = "1" Else tempb = "0"
                        MainProgram.MapData = Mid(MainProgram.MapData, 1, int2 + 6 + Len(str1)) + Replace(LTrim(Str(MainProgram.UserLocation_World)) + "," + LTrim(Str(MainProgram.UserLocation_Continent)) + "," + LTrim(Str(MainProgram.UserLocation_Province)) + "," + LTrim(Str(MainProgram.UserLocation_Area)) + "," + LTrim(Str(MainProgram.UserLocation_Map)) + "," + str1 + "," + Str(MainProgram.UserLocation_Environ) + "," + tempb + "," + LTrim(Str(MainProgram.UserLocation_EastCNCT)) + "," + LTrim(Str(MainProgram.UserLocation_WestCNCT)) + "," + LTrim(Str(MainProgram.UserLocation_NorthCNCT)) + "," + LTrim(Str(MainProgram.UserLocation_SouthCNCT)) + "," + LTrim(Str(MainProgram.UserLocation_UpCNCT)) + "," + LTrim(Str(MainProgram.UserLocation_DownCNCT)), " ", "") + Mid(MainProgram.MapData, int3, MainProgram.MapData.Length)
                        Exit For
                    End If
                Next
            End If
            int2 = InStr(MainProgram.MapData, "CCHAR#" + str1 + "(")
            If int2 > 0 Then
                For int3 = int2 To Len(MainProgram.MapData) Step 1
                    If Mid(MainProgram.MapData, int3, 1) = ")" Then
                        MainProgram.MapData = Mid(MainProgram.MapData, 1, int2 + 6 + Len(str1)) + MainProgram.MapData_CCHAR + Mid(MainProgram.MapData, int3, MainProgram.MapData.Length)
                        Exit For
                    End If
                Next
            End If
            int2 = InStr(MainProgram.MapData, "STATC#" + str1 + "(")
            If int2 > 0 Then
                For int3 = int2 To Len(MainProgram.MapData) Step 1
                    If Mid(MainProgram.MapData, int3, 1) = ")" Then
                        MainProgram.MapData = Mid(MainProgram.MapData, 1, int2 + 6 + Len(str1)) + MainProgram.MapData_STATC + Mid(MainProgram.MapData, int3, MainProgram.MapData.Length)
                        Exit For
                    End If
                Next
            End If
            int2 = InStr(MainProgram.MapData, "DRTEM#" + str1 + "(")
            If int2 > 0 Then
                For int3 = int2 To Len(MainProgram.MapData) Step 1
                    If Mid(MainProgram.MapData, int3, 1) = ")" Then
                        MainProgram.MapData = Mid(MainProgram.MapData, 1, int2 + 6 + Len(str1)) + MainProgram.MapData_DRTEM + Mid(MainProgram.MapData, int3, MainProgram.MapData.Length)
                        Exit For
                    End If
                Next
            End If
        End If
    End Sub
End Module
